@extends('layouts.app')

@section('content')
<!-- Main content -->
<section class="content">
  <div class="row">
    <div class="col-xs-12">
      @include('layouts.utils.success')
      <div class="box">
        <div class="box-header">
          <a href="{{ url('/api_admin/role/create') }}" class="btn btn-primary">添加新角色</a>
        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive no-padding">
          <table class="table table-hover">
            <tr>
              <th style="width: 50px;">ID</th>
              <th>Name</th>
              <th>角色名</th>
              <th>角色描述</th>
              <th>创建日期</th>
              <th>权限</th>
              <th style="width: 120px;">操作</th>
            </tr>
            @forelse($roles as $role)
            <tr>
              <td>{{ $role->id }}</td>
              <td>{{ $role->name }}</td>
              <td>
                <a href="{{ url('/api_admin/role/'.$role->id.'/edit') }}">{{ $role->display_name }}</a>
              </td>
              <td>{{ $role->description }}</td>
              <td>{{ $role->created_at }}</td>
              <td>
                @if(count($role->perms))
                  @foreach($role->perms as $permission)
                    <span class="label label-success">{{ $permission->display_name }}</span>
                  @endforeach
                @else
                  无权限
                @endif
              </td>
              <td>
                <a style="cursor: pointer;" onclick="del({{$role->id}})">删除</a>
                <form id="del-{{ $role->id }}" method="post" action="{{ url('/api_admin/role/'.$role->id) }}">
                  {!! csrf_field() !!}
                  {{ method_field('DELETE') }}
                </form>
              </td>
            </tr>
            @empty
              <tr>
                <td colspan="7" class="text-center">暂无数据</td>
              </tr>
            @endforelse
          </table>
          @include('layouts.utils.del_modal', ['title' => '角色'])
        </div>
        <div class="box-footer">
          {!! $roles->links() !!}
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>
  </div>
</section>
<!-- /.content -->
@endsection

@section('js')
<script type="text/javascript">
  function del(id){
    var formId = 'del-'+id;
    $('#delete-modal').modal();
    $('#del-btn').on('click', function() {
      $('#'+formId).submit();
    });
  }
</script>
@endsection
